package com.example.volleydemo;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

import com.android.volley.VolleyError;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		 volley_get();
		//2015年11月2日 22:57:44
//		volley_post();
		// volley_post_jsonobject();
	}

	// private void volley_post_jsonobject() {
	// String url = "http://api.budejie.com/api/api_open.php?";
	// Map<String, String> map = new HashMap<String, String>();
	// map.put("a", "list");
	// map.put("c", "data");
	// map.put("type", "1");
	// map.put("maxtime", "");
	// JSONObject object = new JSONObject(map);
	// JsonObjectRequest request = new JsonObjectRequest(Method.POST, url,
	// object, new Listener<JSONObject>() {
	//
	// @Override
	// public void onResponse(JSONObject arg0) {
	// Toast.makeText(getApplicationContext(),
	// arg0.toString(), 1).show();
	// Log.e("lcy", "success:" + arg0);
	// }
	// }, new Response.ErrorListener() {
	//
	// @Override
	// public void onErrorResponse(VolleyError arg0) {
	// Toast.makeText(getApplicationContext(),
	// arg0.toString(), 1).show();
	// Log.e("lcy", "error:" + arg0);
	// }
	// });
	// request.setTag(url);
	// MyApplication.getRequestQueue().add(request);
	// }

	private void volley_post() {// 使用post请求，
		String url = "http://api.budejie.com/api/api_open.php?";
		Map<String, String> params = new HashMap<String, String>();
		params.put("a", "list");
		params.put("c", "data");
		params.put("type", "1");
		params.put("maxtime", "");
		VolleyRequest.stringRequestPost(getApplicationContext(), url, url,
				params, new VolleyInterface(this) {

					@Override
					public void mySuccess(String result) {
						Toast.makeText(context,
								"stringRequestPost成功==" + result,
								Toast.LENGTH_LONG).show();
					}

					@Override
					public void myFail(VolleyError arg0) {
						Toast.makeText(context,
								"stringRequestPost失败==" + arg0.toString(),
								Toast.LENGTH_LONG).show();
					}
				});

	}

	private void volley_get() {
		String url = "http://api.budejie.com/api/api_open.php?a=list&c=data&type=1&maxtime=";
		VolleyRequest.stringRequestGet(getApplicationContext(), url, url,
				new VolleyInterface(this) {

					@Override
					public void mySuccess(String result) {
						Toast.makeText(context,
								"stringRequestGet成功==" + result,
								Toast.LENGTH_LONG).show();
					}

					@Override
					public void myFail(VolleyError arg0) {
						Toast.makeText(context,
								"stringRequestGet失败==" + arg0.toString(),
								Toast.LENGTH_LONG).show();
					}
				});
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		MyApplication.getRequestQueue().cancelAll("adfsfdsdfs");
	}
}
